package com.chuanyang.driverh.mainstart.fragment;


import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseFragment;
import com.chuanyang.driverh.mainorder.fragment.OrderFragment;
import com.chuanyang.driverh.mainorder.fragment.WaybillFragment;
import com.chuanyang.driverh.utils.widget.MyViewPager;

import java.util.ArrayList;

public class MyOrderBillFragment   extends BaseFragment implements RadioGroup.OnCheckedChangeListener{

    private ArrayList list;
    private FragmentPagerAdapter adapter;
    private MyViewPager vp_orderbill;
    private OrderFragment orderFragment;
    private WaybillFragment waybillFragment;
    private int position;//

    RadioGroup rg_common;
    RadioButton rb_left;
    RadioButton rb_right;


    @Override
    protected int getLayoutResId() {
        return R.layout.common_frag_tab_two;
    }

    @Override
    protected void initView(View view) {
        rg_common=(RadioGroup)rootView.findViewById(R.id.rg_common);
        rb_left=(RadioButton)rootView.findViewById(R.id.rb_left);
        rb_right=(RadioButton)rootView.findViewById(R.id.rb_right);
        rb_left.setText("我的订单");
        rb_right.setText("我的运单");
    }

    @Override
    protected void initData() {
        vp_orderbill = (MyViewPager) rootView.findViewById(R.id.vp_common);
        list = new ArrayList();
        orderFragment = new OrderFragment();
        waybillFragment = new WaybillFragment();
        list.add(orderFragment);
        list.add(waybillFragment);
        adapter = new FragmentPagerAdapter(getChildFragmentManager());
        vp_orderbill.setAdapter(adapter);
    }

    @Override
    protected void initListener() {
        rg_common.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
        switch (checkedId){
            case R.id.rb_left:
                vp_orderbill.setCurrentItem(0);
                position=0;
                break;
            case R.id.rb_right:
                position=1;
                vp_orderbill.setCurrentItem(1);
                break;
        }
    }

    class FragmentPagerAdapter extends android.support.v4.app.FragmentPagerAdapter {
        public FragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Fragment getItem(int position) {
            return (Fragment) list.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }
    }
}